package com.monogdb;

import com.mongodb.Application;
import com.mongodb.document.Account;
import com.mongodb.document.User;
import com.mongodb.service.AddressService;
import com.mongodb.service.TestService;
import com.mongodb.service.TransactionService;
import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.interceptor.TransactionInterceptor;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Reader;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class test {
    @Autowired
    private AddressService addressService;
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private TestService testService;
    @Autowired
    private TransactionService transactionService;

    @Test
    public void run() {
        try {
        /* User user=new User();
            user.setAge(20);
            user.setName("张");
            Account account=new Account();
            account.setUserId("5c6e46b9b09f9526285be49b");
            account.setMoney(1900d);
            user.setAccount(account);
            mongoTemplate.save(user);*/
           System.out.println(mongoTemplate.findOne(new Query(Criteria.where("_id").is("5c6e48e5b09f9542e08843fe").and("account.userId").is("5c6e46b9b09f9526285be49b")),User.class));
           // transactionService.addUser();
            //transactionService.addUser1();
            //System.out.println(addressService.findAddressDocumentList());
          /*  AddressDocument document = new AddressDocument();
            document.setBuilding("1111");
            document.setCity("成都");
            document.setPincode(1233);
            document.setState("yes");
            addressService.saveAddressDocument(document);*/
            //System.out.println(addressService.findAddressDocument("成都", 1232));
            //System.out.println(addressService.findAddressDocumentByGroup());
            // System.out.println(addressService.findAgregate());
            /*List<GroupTestCollection> groupTestList = new ArrayList<>();
            GroupTestCollection groupTest1 = new GroupTestCollection();
            groupTest1.setX(1);
            GroupTestCollection groupTest2 = new GroupTestCollection();
            groupTest2.setX(1);
            GroupTestCollection groupTest3 = new GroupTestCollection();
            groupTest3.setX(2);
            GroupTestCollection groupTest4 = new GroupTestCollection();
            groupTest4.setX(3);
            GroupTestCollection groupTest5 = new GroupTestCollection();
            groupTest5.setX(3);
            GroupTestCollection groupTest6 = new GroupTestCollection();
            groupTest6.setX(3);
            groupTestList.add(groupTest1);
            groupTestList.add(groupTest2);
            groupTestList.add(groupTest3);
            groupTestList.add(groupTest4);
            groupTestList.add(groupTest5);
            groupTestList.add(groupTest6);
            testService.addGroupTestList(groupTestList);*/
            //testService.reduceGroup1();t
            // testService.aggregate1();
           /* ZipInfo zipInfo = new ZipInfo();
            zipInfo.setCity("东莞");
            zipInfo.setState("舒适");
            zipInfo.setLocation(new double[]{134.12, 123.13});
            zipInfo.setPopulation(13000);
            ZipInfo zipInfo1 = new ZipInfo();
            zipInfo1.setCity("重庆");
            zipInfo1.setState("舒适");
            zipInfo1.setLocation(new double[]{130.15, 121.14});
            zipInfo1.setPopulation(12000);
            ZipInfo zipInfo2 = new ZipInfo();
            zipInfo2.setCity("四川");
            zipInfo2.setState("不安逸");
            zipInfo2.setLocation(new double[]{999.12, 600.13});
            zipInfo2.setPopulation(18000);
            ZipInfo zipInfo3 = new ZipInfo();
            zipInfo3.setCity("北京");
            zipInfo3.setState("极差");
            zipInfo3.setLocation(new double[]{599.12, 400.13});
            zipInfo3.setPopulation(9000);
            List<ZipInfo> list = new ArrayList<>();
            list.add(zipInfo);
            list.add(zipInfo1);
            list.add(zipInfo2);
            list.add(zipInfo3);
            mongoTemplate.insert(list, ZipInfo.class);*/
            //testService.aggregate2();
            // testService.aggregate3();
          /*  Product product = new Product();
            product.setName("巧克力");
            product.setNetPrice(100d);
            product.setSpaceUnits(3);
            mongoTemplate.insert(product);*/
            // testService.aggregate4();
            //testService.aggregation5();
            // testService.aggregation6();
           /* InventoryItem inventoryItem = new InventoryItem();
            inventoryItem.setItem("裙子");
            inventoryItem.setDescription("这是一条漂亮得裙子");
            inventoryItem.setQty(300);
            inventoryItem.setDiscount(5);
            mongoTemplate.insert(inventoryItem);*/
            // testService.aggregation7();
           /* Book book = new Book();
            book.setTitle("老人与海");
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("middle", "海明威");
            book.setAuthor(jsonObject);
            mongoTemplate.insert(book);*/
            // testService.aggregation8();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
